{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to Quantitative Finance\n",
    "\n",
    "Copyright (c) 2019 Python Charmers Pty Ltd, Australia, <https://pythoncharmers.com>. All rights reserved.\n",
    "\n",
    "<img src=\"img/python_charmers_logo.png\" width=\"300\" alt=\"Python Charmers Logo\">\n",
    "\n",
    "Published under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license. See `LICENSE.md` for details.\n",
    "\n",
    "Sponsored by Tibra Global Services, <https://tibra.com>\n",
    "\n",
    "<img src=\"img/tibra_logo.png\" width=\"300\" alt=\"Tibra Logo\">\n",
    "\n",
    "\n",
    "## Module 2.2: Modelling Techniques\n",
    "\n",
    "### 2.2.2 ARIMA\n",
    "\n",
    "In this module we will introduce ARIMA, an improvement over the ARMA model we reviewed in a past module (1.6.4). We will quickly review the key parts of ARMA as we build to the new ARIMA model:\n",
    "\n",
    "\n",
    "### Autoregressive Model (AR)\n",
    "\n",
    "The autoregressive model is used for predicting the value of a variable in a time series. We use the annotation $AR(p)$ for an autoregressive model with $p$ periods.\n",
    "\n",
    "$AR(p) X_t = c + \\sum_{i=1}^p{\\beta_i X_{t-i}} + u_t$\n",
    "\n",
    "We can simplify in the case of an AR(1) model, that is $p=1$. This simplifies further if we also assume a zero mean (which can be done by demeaning the data beforehand, giving $c=0$) and an error term $u$ that is white noise:\n",
    "\n",
    "$AR(1) = \\beta X_{t-1}$\n",
    "\n",
    "### Moving Average (MA)\n",
    "\n",
    "A Moving Average (MA) model is given as:\n",
    "\n",
    "$MA(q) X_t = \\mu + \\epsilon_{t} + \\sum_{i=1}^{q}\\theta_i\\epsilon_{t-i}$\n",
    "\n",
    "and specifically the MA(1) process as:\n",
    "\n",
    "$MA(1)X_t = \\epsilon_t + \\theta \\epsilon_{t-1}$\n",
    "\n",
    "Here, the values $\\epsilon_t$ are the error terms for a given time step $t$ and $\\mu$ is the average of the values of $X$.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ARMA model\n",
    "\n",
    "The ARMA model is a combination of both the AR model and the MA. It is quite a simple combination - we just concatenate the models, but the training of the model does become more complicated. \n",
    "\n",
    "An $ARMA(p, q)$ model, where $p$ is the lag in the autoregressive model and $q$ is the lag in the moving-average model, given as:\n",
    "\n",
    "$X_t = c + \\epsilon_t + \\sum_{i=1}^{p}{\\beta_i X_{t-i}} + \\sum_{i=1}^{q}\\theta_i\\epsilon_{t-i}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Extended Exercise\n",
    "\n",
    "It is often argued that cryptocurrency prices for non-Bitcoin coins \"follow\" Bitcoin, i.e. they lag. Test this hypothesis on a daily level by checking if the values for Ethereum (ETH) and Ripple (XRP) can be modelled using a ARMA model. Test different values for p and q and find the best model.\n",
    "\n",
    "You can get daily prices from Quandl, via BITFINEX: https://www.quandl.com/data/BITFINEX-Bitfinex\n",
    "\n",
    "You can review module 1.6.4 for code on how to run the ARMA model in statsmodels."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\base\\model.py:604: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\base\\model.py:604: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\base\\model.py:604: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\base\\model.py:604: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\base\\model.py:604: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\base\\model.py:604: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "XRP:  {'bic':              0            1            2\n",
      "0  1299.589528 -1630.192257 -3575.422884\n",
      "1 -7854.080210 -7893.240446 -7892.451647\n",
      "2 -7888.674767 -7900.853077 -7886.244724\n",
      "3 -7884.022783 -7891.970767 -7898.979903\n",
      "4 -7935.348262 -7916.563303 -7927.404542, 'bic_min_order': (4, 0)}\n",
      "ETH: {'bic':               0             1             2\n",
      "0  47430.355561  43798.197288  40825.073345\n",
      "1  31475.917478  31482.202234  31489.359942\n",
      "2  31482.144164  31479.759838  31486.869773\n",
      "3  31489.322247  31486.929108  31490.332885\n",
      "4  31497.149284  31494.754230  31489.856497, 'bic_min_order': (1, 0)}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:471: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:471: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:471: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:471: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:471: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:471: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\base\\model.py:604: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "c:\\Python311\\Lib\\site-packages\\statsmodels\\base\\model.py:604: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n"
     ]
    }
   ],
   "source": [
    "#From solutions\n",
    "%run setup.ipy\n",
    "\n",
    "import quandl\n",
    "import my_secrets\n",
    "quandl.ApiConfig.api_key = my_secrets.QUANDL_API_KEY\n",
    "\n",
    "xrp = quandl.get(\"BITFINEX/XRPUSD\")[\"Last\"]\n",
    "eth = quandl.get(\"BITFINEX/ETHUSD\")[\"Last\"]\n",
    "\n",
    "# Should we replace the index? Some dates are missing so we can't set a frquency to 'D' without actually\n",
    "# replacing the entire index? This generates a lot of warnings...\n",
    "\n",
    "\n",
    "# When we've played with values a bit, we can then use the below.\n",
    "from statsmodels.tsa import stattools\n",
    "xrp_stats = stattools.arma_order_select_ic(xrp) \n",
    "eth_stats = stattools.arma_order_select_ic(eth) \n",
    "print(\"XRP: \", xrp_stats)\n",
    "print(\"ETH:\", eth_stats)\n",
    "\n",
    "from statsmodels import api as sms\n",
    "xrp_model = sms.tsa.ARIMA(xrp, order=(4, 0, 2))\n",
    "eth_model = sms.tsa.ARIMA(eth, order=(3, 0, 2))\n",
    "\n",
    "xrp_results = xrp_model.fit()\n",
    "eth_results = eth_model.fit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>SARIMAX Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>         <td>Last</td>       <th>  No. Observations:  </th>   <td>2387</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>            <td>ARIMA(4, 0, 2)</td>  <th>  Log Likelihood     </th> <td>3994.813</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>            <td>Fri, 09 Feb 2024</td> <th>  AIC                </th> <td>-7973.627</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                <td>00:49:18</td>     <th>  BIC                </th> <td>-7927.405</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Sample:</th>                  <td>0</td>        <th>  HQIC               </th> <td>-7956.807</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                      <td> - 2387</td>     <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>        <td>opg</td>       <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "     <td></td>       <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>const</th>  <td>    0.4986</td> <td>    0.132</td> <td>    3.766</td> <td> 0.000</td> <td>    0.239</td> <td>    0.758</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L1</th>  <td>    1.2222</td> <td>    0.044</td> <td>   27.640</td> <td> 0.000</td> <td>    1.135</td> <td>    1.309</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L2</th>  <td>   -0.6241</td> <td>    0.066</td> <td>   -9.429</td> <td> 0.000</td> <td>   -0.754</td> <td>   -0.494</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L3</th>  <td>    0.5904</td> <td>    0.047</td> <td>   12.681</td> <td> 0.000</td> <td>    0.499</td> <td>    0.682</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L4</th>  <td>   -0.2025</td> <td>    0.006</td> <td>  -35.731</td> <td> 0.000</td> <td>   -0.214</td> <td>   -0.191</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L1</th>  <td>   -0.0934</td> <td>    0.048</td> <td>   -1.961</td> <td> 0.050</td> <td>   -0.187</td> <td>-5.03e-05</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L2</th>  <td>    0.3363</td> <td>    0.046</td> <td>    7.313</td> <td> 0.000</td> <td>    0.246</td> <td>    0.426</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>sigma2</th> <td>    0.0021</td> <td> 1.43e-05</td> <td>  143.853</td> <td> 0.000</td> <td>    0.002</td> <td>    0.002</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Ljung-Box (L1) (Q):</th>     <td>0.00</td> <th>  Jarque-Bera (JB):  </th> <td>418606.36</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Q):</th>                <td>0.99</td> <th>  Prob(JB):          </th>   <td>0.00</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Heteroskedasticity (H):</th> <td>0.21</td> <th>  Skew:              </th>   <td>2.83</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(H) (two-sided):</th>    <td>0.00</td> <th>  Kurtosis:          </th>   <td>67.63</td>  \n",
       "</tr>\n",
       "</table><br/><br/>Warnings:<br/>[1] Covariance matrix calculated using the outer product of gradients (complex-step)."
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                               SARIMAX Results                                \n",
       "==============================================================================\n",
       "Dep. Variable:                   Last   No. Observations:                 2387\n",
       "Model:                 ARIMA(4, 0, 2)   Log Likelihood                3994.813\n",
       "Date:                Fri, 09 Feb 2024   AIC                          -7973.627\n",
       "Time:                        00:49:18   BIC                          -7927.405\n",
       "Sample:                             0   HQIC                         -7956.807\n",
       "                               - 2387                                         \n",
       "Covariance Type:                  opg                                         \n",
       "==============================================================================\n",
       "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "const          0.4986      0.132      3.766      0.000       0.239       0.758\n",
       "ar.L1          1.2222      0.044     27.640      0.000       1.135       1.309\n",
       "ar.L2         -0.6241      0.066     -9.429      0.000      -0.754      -0.494\n",
       "ar.L3          0.5904      0.047     12.681      0.000       0.499       0.682\n",
       "ar.L4         -0.2025      0.006    -35.731      0.000      -0.214      -0.191\n",
       "ma.L1         -0.0934      0.048     -1.961      0.050      -0.187   -5.03e-05\n",
       "ma.L2          0.3363      0.046      7.313      0.000       0.246       0.426\n",
       "sigma2         0.0021   1.43e-05    143.853      0.000       0.002       0.002\n",
       "===================================================================================\n",
       "Ljung-Box (L1) (Q):                   0.00   Jarque-Bera (JB):            418606.36\n",
       "Prob(Q):                              0.99   Prob(JB):                         0.00\n",
       "Heteroskedasticity (H):               0.21   Skew:                             2.83\n",
       "Prob(H) (two-sided):                  0.00   Kurtosis:                        67.63\n",
       "===================================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Covariance matrix calculated using the outer product of gradients (complex-step).\n",
       "\"\"\""
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xrp_results.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>SARIMAX Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>         <td>Last</td>       <th>  No. Observations:  </th>    <td>2814</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>            <td>ARIMA(3, 0, 2)</td>  <th>  Log Likelihood     </th> <td>-15717.368</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>            <td>Fri, 09 Feb 2024</td> <th>  AIC                </th>  <td>31448.736</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                <td>00:49:48</td>     <th>  BIC                </th>  <td>31490.333</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Sample:</th>                  <td>0</td>        <th>  HQIC               </th>  <td>31463.747</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                      <td> - 2814</td>     <th>                     </th>      <td> </td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>        <td>opg</td>       <th>                     </th>      <td> </td>    \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "     <td></td>       <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>const</th>  <td> 1009.0201</td> <td> 1315.347</td> <td>    0.767</td> <td> 0.443</td> <td>-1569.012</td> <td> 3587.052</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L1</th>  <td>   -0.4165</td> <td>    0.011</td> <td>  -38.570</td> <td> 0.000</td> <td>   -0.438</td> <td>   -0.395</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L2</th>  <td>    0.4609</td> <td>    0.008</td> <td>   57.773</td> <td> 0.000</td> <td>    0.445</td> <td>    0.477</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L3</th>  <td>    0.9512</td> <td>    0.010</td> <td>   91.210</td> <td> 0.000</td> <td>    0.931</td> <td>    0.972</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L1</th>  <td>    1.4376</td> <td>    0.009</td> <td>  154.759</td> <td> 0.000</td> <td>    1.419</td> <td>    1.456</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L2</th>  <td>    0.9717</td> <td>    0.009</td> <td>  107.671</td> <td> 0.000</td> <td>    0.954</td> <td>    0.989</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>sigma2</th> <td> 4109.7234</td> <td>   36.911</td> <td>  111.343</td> <td> 0.000</td> <td> 4037.380</td> <td> 4182.067</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Ljung-Box (L1) (Q):</th>     <td>5.08</td>  <th>  Jarque-Bera (JB):  </th> <td>34153.62</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Q):</th>                <td>0.02</td>  <th>  Prob(JB):          </th>   <td>0.00</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Heteroskedasticity (H):</th> <td>11.55</td> <th>  Skew:              </th>   <td>-0.67</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(H) (two-sided):</th>    <td>0.00</td>  <th>  Kurtosis:          </th>   <td>20.02</td> \n",
       "</tr>\n",
       "</table><br/><br/>Warnings:<br/>[1] Covariance matrix calculated using the outer product of gradients (complex-step)."
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                               SARIMAX Results                                \n",
       "==============================================================================\n",
       "Dep. Variable:                   Last   No. Observations:                 2814\n",
       "Model:                 ARIMA(3, 0, 2)   Log Likelihood              -15717.368\n",
       "Date:                Fri, 09 Feb 2024   AIC                          31448.736\n",
       "Time:                        00:49:48   BIC                          31490.333\n",
       "Sample:                             0   HQIC                         31463.747\n",
       "                               - 2814                                         \n",
       "Covariance Type:                  opg                                         \n",
       "==============================================================================\n",
       "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "const       1009.0201   1315.347      0.767      0.443   -1569.012    3587.052\n",
       "ar.L1         -0.4165      0.011    -38.570      0.000      -0.438      -0.395\n",
       "ar.L2          0.4609      0.008     57.773      0.000       0.445       0.477\n",
       "ar.L3          0.9512      0.010     91.210      0.000       0.931       0.972\n",
       "ma.L1          1.4376      0.009    154.759      0.000       1.419       1.456\n",
       "ma.L2          0.9717      0.009    107.671      0.000       0.954       0.989\n",
       "sigma2      4109.7234     36.911    111.343      0.000    4037.380    4182.067\n",
       "===================================================================================\n",
       "Ljung-Box (L1) (Q):                   5.08   Jarque-Bera (JB):             34153.62\n",
       "Prob(Q):                              0.02   Prob(JB):                         0.00\n",
       "Heteroskedasticity (H):              11.55   Skew:                            -0.67\n",
       "Prob(H) (two-sided):                  0.00   Kurtosis:                        20.02\n",
       "===================================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Covariance matrix calculated using the outer product of gradients (complex-step).\n",
       "\"\"\""
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eth_results.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*For solutions, see `solutions/arma_cryptocurrency.py`*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### The ARIMA model\n",
    "\n",
    "One of the issues with the ARMA model is that it requires data to be stationary before the algorithm begins. A normal step for turning non-stationary data into stationary data is to difference the data, either once or twice. Therefore, a normal process is to difference the data and then run ARMA. A problem with this is that we have a two step methodology to describe. ARIMA captures this idea in a single model.\n",
    "\n",
    "The ARIMA model is a more general form of the ARMA model. Specifically, ARMA(p, q) is an ARIMA(p, 0, q) model. The $p$ and $q$ values are the same as the ARMA model. The middle parameter is $d$, for differencing. The ARIMA model will apply differencing to turn a non-stationary dataset into a stationary one, allowing the AR and MA processes to model them better. That's the same as our two step process above, just captured nicely. And a lot more useful.\n",
    "\n",
    "That gives the full ARIMA model as:\n",
    "\n",
    "$ARIMA(p, d, q)$\n",
    "\n",
    "where $p$ is the lag in the autoregressive model and $q$ is the lag in the moving-average model, and $d$ is the order of differencing applied (i.e. how many times to difference the data to get a stationary series).\n",
    "\n",
    "The ARIMA model can also be identified by having components \"turned off\", i.e. set to zero. We saw above that ARIMA(p, 0, q) is simply the ARMA(p, q) model. Further, ARIMA(0, 0, q) is simply MA(q). ARIMA(0, 1, 1) is IMA(1, 1), although that is more obscure than other variants you'll see."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Exercise\n",
    "\n",
    "1. What can the ARIMA(1, 0, 0) model also be known as?\n",
    "2. What does an ARIMA(0, 0, 0) model actually model? Hint: use the ARMA equation, and set p and q to zero.\n",
    "3. What does an ARIMA(0, 1, 0) model represent - i.e. what other term have we seen that refers to the same idea?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. An AR(1) model\n",
    "2. Constant mean plus white noise\n",
    "3. Difference model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*For solutions, see `solutions/arima_types.py`*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Extended Exercise\n",
    "\n",
    "The ARIMA model is implemented in statsmodels under `statsmodels.tsa.arima_model.ARIMA` with a similar use case to the `ARMA` model previously used. Perform an ARIMA modelling on the cryptocurrency data from the previous exercise.\n",
    "\n",
    "Normally, the value for $d$ is determined before running the model, but performing a test of stationarity. See Module 1.6.2 for information on performing these tests. Simply difference the data, check for stationarity, and if it isn't, difference it again. Values more than 3 are abnormal - if you still aren't getting stationary data at that point, check your assumptions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\marin\\Anaconda3\\lib\\site-packages\\statsmodels\\tsa\\stattools.py:1685: FutureWarning: The behavior of using lags=None will change in the next release. Currently lags=None is the same as lags='legacy', and so a sample-size lag length is used. After the next release, the default will change to be the same as lags='auto' which uses an automatic lag length selection method. To silence this warning, either use 'auto' or 'legacy'\n",
      "  warn(msg, FutureWarning)\n",
      "C:\\Users\\marin\\Anaconda3\\lib\\site-packages\\statsmodels\\tsa\\stattools.py:1708: InterpolationWarning: p-value is smaller than the indicated p-value\n",
      "  warn(\"p-value is smaller than the indicated p-value\", InterpolationWarning)\n",
      "C:\\Users\\marin\\Anaconda3\\lib\\site-packages\\statsmodels\\tsa\\stattools.py:1708: InterpolationWarning: p-value is smaller than the indicated p-value\n",
      "  warn(\"p-value is smaller than the indicated p-value\", InterpolationWarning)\n",
      "C:\\Users\\marin\\Anaconda3\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:219: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.\n",
      "  ' ignored when e.g. forecasting.', ValueWarning)\n",
      "C:\\Users\\marin\\Anaconda3\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:219: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.\n",
      "  ' ignored when e.g. forecasting.', ValueWarning)\n",
      "C:\\Users\\marin\\Anaconda3\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:219: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.\n",
      "  ' ignored when e.g. forecasting.', ValueWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "XRP p_value: 0.01\n",
      "ETH p_value: 0.01\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>ARMA Model Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>       <td>Last</td>       <th>  No. Observations:  </th>    <td>2126</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>            <td>ARMA(3, 1)</td>    <th>  Log Likelihood     </th> <td>-11896.681</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Method:</th>             <td>css-mle</td>     <th>  S.D. of innovations</th>   <td>65.071</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>          <td>Sat, 19 Feb 2022</td> <th>  AIC                </th>  <td>23805.363</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>              <td>14:48:00</td>     <th>  BIC                </th>  <td>23839.335</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Sample:</th>                <td>0</td>        <th>  HQIC               </th>  <td>23817.798</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                       <td> </td>        <th>                     </th>      <td> </td>    \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "       <td></td>         <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>const</th>      <td>  980.3539</td> <td>  770.587</td> <td>    1.272</td> <td> 0.203</td> <td> -529.970</td> <td> 2490.678</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L1.Last</th> <td>    0.1663</td> <td>    0.050</td> <td>    3.296</td> <td> 0.001</td> <td>    0.067</td> <td>    0.265</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L2.Last</th> <td>    0.8629</td> <td>    0.040</td> <td>   21.468</td> <td> 0.000</td> <td>    0.784</td> <td>    0.942</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L3.Last</th> <td>   -0.0318</td> <td>    0.023</td> <td>   -1.395</td> <td> 0.163</td> <td>   -0.076</td> <td>    0.013</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L1.Last</th> <td>    0.8140</td> <td>    0.046</td> <td>   17.794</td> <td> 0.000</td> <td>    0.724</td> <td>    0.904</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<caption>Roots</caption>\n",
       "<tr>\n",
       "    <td></td>   <th>            Real</th>  <th>         Imaginary</th> <th>         Modulus</th>  <th>        Frequency</th>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AR.1</th> <td>           1.0014</td> <td>          +0.0000j</td> <td>           1.0014</td> <td>           0.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AR.2</th> <td>          -1.1509</td> <td>          +0.0000j</td> <td>           1.1509</td> <td>           0.5000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AR.3</th> <td>          27.2954</td> <td>          +0.0000j</td> <td>          27.2954</td> <td>           0.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>MA.1</th> <td>          -1.2285</td> <td>          +0.0000j</td> <td>           1.2285</td> <td>           0.5000</td>\n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                              ARMA Model Results                              \n",
       "==============================================================================\n",
       "Dep. Variable:                   Last   No. Observations:                 2126\n",
       "Model:                     ARMA(3, 1)   Log Likelihood              -11896.681\n",
       "Method:                       css-mle   S.D. of innovations             65.071\n",
       "Date:                Sat, 19 Feb 2022   AIC                          23805.363\n",
       "Time:                        14:48:00   BIC                          23839.335\n",
       "Sample:                             0   HQIC                         23817.798\n",
       "                                                                              \n",
       "==============================================================================\n",
       "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "const        980.3539    770.587      1.272      0.203    -529.970    2490.678\n",
       "ar.L1.Last     0.1663      0.050      3.296      0.001       0.067       0.265\n",
       "ar.L2.Last     0.8629      0.040     21.468      0.000       0.784       0.942\n",
       "ar.L3.Last    -0.0318      0.023     -1.395      0.163      -0.076       0.013\n",
       "ma.L1.Last     0.8140      0.046     17.794      0.000       0.724       0.904\n",
       "                                    Roots                                    \n",
       "=============================================================================\n",
       "                  Real          Imaginary           Modulus         Frequency\n",
       "-----------------------------------------------------------------------------\n",
       "AR.1            1.0014           +0.0000j            1.0014            0.0000\n",
       "AR.2           -1.1509           +0.0000j            1.1509            0.5000\n",
       "AR.3           27.2954           +0.0000j           27.2954            0.0000\n",
       "MA.1           -1.2285           +0.0000j            1.2285            0.5000\n",
       "-----------------------------------------------------------------------------\n",
       "\"\"\""
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#From solutions\n",
    "# Use KPSS to test for stationarity.\n",
    "from statsmodels.tsa.stattools import kpss\n",
    "\n",
    "kpss_stat, p_value, lags, crit = kpss(xrp)\n",
    "print(\"XRP p_value:\", p_value)\n",
    "\n",
    "kpss_stat, p_value, lags, crit = kpss(eth)\n",
    "print(\"ETH p_value:\", p_value)\n",
    "\n",
    "\n",
    "from statsmodels.tsa.arima_model import ARIMA as arima\n",
    "\n",
    "xrp_model_arima = arima(xrp, order=(4,1, 2))  #Remember if we use d=0 we're back to using the ARMA model!\n",
    "eth_model_arima = sms.tsa.ARMA(eth, order=(3, 1, 2))\n",
    "\n",
    "xrp_results_arima = xrp_model_arima.fit()\n",
    "eth_results_arima = eth_model_arima.fit()\n",
    "\n",
    "xrp_results_arima.summary()\n",
    "eth_results_arima.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*For solutions, see `solutions/arima_cryptocurrency.py`*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Choosing parameters\n",
    "\n",
    "When choosing parameters for the ARIMA model, the normal rule of thumb is \"keep them small\". Robert Nau summarised this as:\n",
    "\n",
    "<i>In most cases either p is zero or q is zero, and p+q is less than or equal to 3, so there aren’t very many terms on the right-hand-side of this equation</i>\n",
    "\n",
    "<small>See https://people.duke.edu/~rnau/Notes_on_nonseasonal_ARIMA_models--Robert_Nau.pdf</small>\n",
    "\n",
    "Galit Shmueli has some further insight into this problem in her video on YouTube: https://www.youtube.com/watch?v=0xHf-SJ9Z9U\n",
    "\n",
    "When performing a grid search (in other words, \"try all combinations of these values for the parameters\") you can keep your search space small by trying 0, 1, 2 and 3 as the only options (and just 0, 1, 2 for $d$). If that model isn't sufficient, **and** you have a good theoretical reason for a different value. For seasonal change, for instance, if you suspect a yearly trend (this June's data will be dependent on last June's), then seasonal ARIMA is needed, which we will cover later in this module."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import quandl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "from statsmodels import api as sms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "employment = quandl.get(\"FRED/NROUST\").diff().dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "changes = employment.diff().dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from statsmodels.tsa.arima_model import ARIMA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\marin\\Anaconda3\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:165: ValueWarning: No frequency information was provided, so inferred frequency QS-OCT will be used.\n",
      "  % freq, ValueWarning)\n",
      "C:\\Users\\marin\\Anaconda3\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:165: ValueWarning: No frequency information was provided, so inferred frequency QS-OCT will be used.\n",
      "  % freq, ValueWarning)\n"
     ]
    }
   ],
   "source": [
    "model = ARIMA(changes, order=(1, 1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "results = model.fit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>ARIMA Model Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>      <td>D.Value</td>     <th>  No. Observations:  </th>    <td>329</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>          <td>ARIMA(1, 1, 1)</td>  <th>  Log Likelihood     </th> <td>1018.750</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Method:</th>             <td>css-mle</td>     <th>  S.D. of innovations</th>   <td>0.011</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>          <td>Sat, 19 Feb 2022</td> <th>  AIC                </th> <td>-2029.500</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>              <td>14:49:49</td>     <th>  BIC                </th> <td>-2014.316</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Sample:</th>           <td>10-01-1949</td>    <th>  HQIC               </th> <td>-2023.443</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                 <td>- 10-01-2031</td>   <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "        <td></td>           <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>const</th>         <td> 3.741e-07</td> <td> 5.24e-06</td> <td>    0.071</td> <td> 0.943</td> <td>-9.89e-06</td> <td> 1.06e-05</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L1.D.Value</th> <td>   -0.1977</td> <td>    0.054</td> <td>   -3.661</td> <td> 0.000</td> <td>   -0.304</td> <td>   -0.092</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L1.D.Value</th> <td>   -1.0000</td> <td>    0.008</td> <td> -125.172</td> <td> 0.000</td> <td>   -1.016</td> <td>   -0.984</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<caption>Roots</caption>\n",
       "<tr>\n",
       "    <td></td>   <th>            Real</th>  <th>         Imaginary</th> <th>         Modulus</th>  <th>        Frequency</th>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AR.1</th> <td>          -5.0574</td> <td>          +0.0000j</td> <td>           5.0574</td> <td>           0.5000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>MA.1</th> <td>           1.0000</td> <td>          +0.0000j</td> <td>           1.0000</td> <td>           0.0000</td>\n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                             ARIMA Model Results                              \n",
       "==============================================================================\n",
       "Dep. Variable:                D.Value   No. Observations:                  329\n",
       "Model:                 ARIMA(1, 1, 1)   Log Likelihood                1018.750\n",
       "Method:                       css-mle   S.D. of innovations              0.011\n",
       "Date:                Sat, 19 Feb 2022   AIC                          -2029.500\n",
       "Time:                        14:49:49   BIC                          -2014.316\n",
       "Sample:                    10-01-1949   HQIC                         -2023.443\n",
       "                         - 10-01-2031                                         \n",
       "=================================================================================\n",
       "                    coef    std err          z      P>|z|      [0.025      0.975]\n",
       "---------------------------------------------------------------------------------\n",
       "const          3.741e-07   5.24e-06      0.071      0.943   -9.89e-06    1.06e-05\n",
       "ar.L1.D.Value    -0.1977      0.054     -3.661      0.000      -0.304      -0.092\n",
       "ma.L1.D.Value    -1.0000      0.008   -125.172      0.000      -1.016      -0.984\n",
       "                                    Roots                                    \n",
       "=============================================================================\n",
       "                  Real          Imaginary           Modulus         Frequency\n",
       "-----------------------------------------------------------------------------\n",
       "AR.1           -5.0574           +0.0000j            5.0574            0.5000\n",
       "MA.1            1.0000           +0.0000j            1.0000            0.0000\n",
       "-----------------------------------------------------------------------------\n",
       "\"\"\""
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Exercise\n",
    "\n",
    "Play around with the values for order and test out several types. How does the summary results change? What extra variables are added? How are they added, for instance, when you set $p=2$?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note: There are no solutions for this exercise - just try different values and examine the result."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Testing your ARIMA model\n",
    "\n",
    "With your ARIMA model, you can test the residuals of the model to confirm they are white noise, or whether there is an additional correlation in the residuals that needs to be modelled. The Ljung-Box tests the following hypotheses:\n",
    "\n",
    "$H_0$: The data are independently distributed\n",
    "\n",
    "$H_A$: The data is not independently distributed, that is that they have a serial correlation.\n",
    "\n",
    "Such a serial correlation indicates that the ARIMA model hasn't done its job well, indicative of a bad choice of parameters for $p$ and $q$, mainly $q$.\n",
    "\n",
    "The test itself is:\n",
    "\n",
    "$Q = n(n + 2)\\sum_{k=1}^{h}\\frac{p^2}{n-k}$\n",
    "\n",
    "Where $n$ is the size of the dataset, $h$ is the number of lags being tested"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "from statsmodels.stats.diagnostic import acorr_ljungbox"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_statistics, p_values = acorr_ljungbox(results.resid)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False, False, False, False, False, False,\n",
       "       False, False, False, False])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p_values > 0.05"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Exercise\n",
    "\n",
    "Review carefully these results, compared against the hypothesis stated for the Ljung-Box test. What are the results saying?\n",
    "\n",
    "Hint: for documentation on the function itself, see https://www.statsmodels.org/stable/generated/statsmodels.stats.diagnostic.acorr_ljungbox.html"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*For solutions, see `solutions/ljungbox.py`*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Prediction with ARIMA\n",
    "\n",
    "ARIMA models can be used for predicting future values. \n",
    "The prediction confidence interval from an ARIMA model will be wider for data with a higher volatility.\n",
    "\n",
    "An ARIMA model is often harder to analyse than a simple Linear Regression model. For this reason, analysis of the fitted parameters (and meta-parameters, internal states of the model) are not often performed to understand \"why\" the model fit the way it did. Compare this to Linear Regression models, where we can interpret the $\\beta$ values to understand why the model fit the way it did."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>2030-10-01</td>\n",
       "      <td>0.000026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2031-01-01</td>\n",
       "      <td>0.000039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2031-04-01</td>\n",
       "      <td>0.000048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2031-07-01</td>\n",
       "      <td>0.000051</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2031-10-01</td>\n",
       "      <td>0.000042</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               Value\n",
       "Date                \n",
       "2030-10-01  0.000026\n",
       "2031-01-01  0.000039\n",
       "2031-04-01  0.000048\n",
       "2031-07-01  0.000051\n",
       "2031-10-01  0.000042"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "changes.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>2000-01-01</td>\n",
       "      <td>-0.000088</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2000-04-01</td>\n",
       "      <td>-0.000089</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2000-07-01</td>\n",
       "      <td>-0.000085</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2000-10-01</td>\n",
       "      <td>-0.000069</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               Value\n",
       "Date                \n",
       "2000-01-01 -0.000088\n",
       "2000-04-01 -0.000089\n",
       "2000-07-01 -0.000085\n",
       "2000-10-01 -0.000069"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "changes[\"2000\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Predict values within the sample\n",
    "from datetime import datetime\n",
    "\n",
    "start_date = datetime(2000, 1, 1)\n",
    "end_date = datetime(2001, 10, 1)\n",
    "\n",
    "y_pred = results.predict(start_date, end_date)\n",
    "y_pred.name = \"Predictions\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "%run setup.ipy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXEAAAEUCAYAAADdvgZNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF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j7UmAJ0BM4D3gk/LBHCF24hfDyv3rIu0BHM8sDTgdec/cd7r4TeI3QlcZEYlILbvu4++tAaWvml8TX5DFxMysARgFzgG7uvglCGztQf1JAT2Bdg9XWh5cdarlIzDvCbV8kKppU4mbWFngKuNpD14o45EMPsswPs1wkprXAti8SFRGXuJmlE9qI/+7uT4cXb6l/qxj+ujW8fD3Qu8HqvYCNh1kuErNaaNsXiYpIj04x4E/AEne/r8FdzxGa/YPw12cbLP9a+JP6ccDu8FvOfwOnmVmn8Aeap4WXicSkFtz2RaIiopN9zOwkYCahi6zXhRffQGhs8F9APrAWuMjdd4Q3/AcIfWhZDlzu7kXh5/p6eF2AKR6+JrNILGrhbX8mMIjQ7C3bgSvcXTsxckR0xqaISBzTGZsiInFMJS4iEsdU4iIicUwlLiISx1TiIiJxTCUuIhLHVOIiInFMJS4iEsf+P1zjoQ+RQm3HAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAEiCAYAAAAcSqIJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3dd3xUdf798dc7hSSEhEDogRA6CFKDvS3Y14q6Lu6qrAX72tb1p67rusX1q+5aFhuWtayI2MDu2gtrCyR0kF4SSgglISF1Pr8/ZtCogUBmkjvlPB+PPJjcmXvnjN45ufO5d+415xwiIhKd4rwOICIizUclLyISxVTyIiJRTCUvIhLFVPIiIlFMJS8iEsVU8iIhZGZ/MrP/eJ1DZBeVvEQdM/vYzLaaWdJePHaCmX3eErlEvKCSl6hiZjnA4YADTvE0jEgYUMlLtDkP+BJ4Cjh/10Qz62Fm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evbyOIyJRJmyGayorK8nMzIypggcwMzIzM2PyE4yINL+wKXkg5gp+l1h93SKy91ZtLm/SfCEpeTP7nZm5wBkgI9JRRx3Fu++++4Np9913H5dffvluH69j/UWkuTnnePbL1Zxw/2dNmj/okjezHsAx+C/GELHGjx/P1KlTfzBt6tSpjB8/3qNEIhLrNmyv5Px/f8Ot0+eTm9OuScsIxZb8vcDvafhamRHjzDPP5I033qCqqgqAVatWUVRUxJQpU8jNzWXw4MHcdtttDc7bpk2b726/9NJLTJgwAYDi4mLOOOMMRo8ezejRo5k5c2azvw4RiQ4zCgo59t5P+HplCX85dTDPXHBAk5YT1NE1ZnYK/kvwzWlsXNnMJgITAbKzs/f42NtfX8DCotJgov3Eft3Sue3kwbu9PzMzkwMOOIB33nmHU089lalTp3L22Wdz00030b59e+rq6hg7dixz585l6NChe/WcV199Nddeey2HHXYYa9as4bjjjmPRokWhekkiEoW2lldz64z5vDF3PSOyM/jnL4bTq0Nqk5fXaMmb2fvUu1p9PbcANwPH7s0TOecm479QN7m5uWG51b9ryGZXyT/55JNMmzaNyZMnU1tby/r161m4cOFel/z777/PwoXfX7uktLSUsrIy0tLSmusliEgE+2jJJm58aS5byqu54bgBXHJEbxLigxtwabTknXNHNzTdzPYHegG7tuK7A7PN7ADn3IZgQu1pi7s5nXbaaVx33XXMnj2bnTt30q5dO+655x6++eYb2rVrx4QJExo81LH+p5j69/t8Pr744gtSUlJaJL+IRKbyqlr+9tYipny1hv6d2/DkhNEMyWobkmU3+U+Ec26ec66Tcy7HOZcDrANGBlvwXmrTpg1HHXUUF1xwAePHj6e0tJTU1FTatm3Lxo0befvttxucr3PnzixatAifz8err7763fRjjz2WSZMmffd7QUFBs78GEYkseau2cML9n/H812uYeERvXrvysJAVPITRN17Dxfjx4xk3bhxTp05l4MCBjBgxgsGDB9O7d28OPfTQBue58847Oemkk+jRowdDhgxhx44dADzwwANcccUVDB06lNraWo444ggeeeSRlnw5IhKmqmrruO/9pTz6yXK6ZaQw9eKDO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gW+ADkBP4FkgNXD3lc65/5nZl/ivzboS/1kkHwDuBI4CkoAHnXOPttiLEGkilbxEvR+XfGDaVvzfLi0DfM65SjPrBzzvnMs1s6OA3znnTgo8fiLQyTn3VzNLAmbi/xbryhZ9MSL7KMHrACIe2XU2yERgkpkNB+qA/rt5/LHAUDM7M/B7W/wX/lDJS1hTyUvMCQzX1OE/M+RtwEZgGP59VJW7mw24SueSkUijHa8SU8ysI/AIMMn5xyrbAuudcz78l96LDzy0DEirN+u7wGWB0wpjZv3NLBWRMKcteYkFKWZWgH9ophb/jtZdpwV+CHjZzM4CPgLKA9PnArVmNgd4Crgf/xE3swNnkizm+0v6iYQt7XgVEYliGq4REYliKnkRkSimkhcRiWIqeRGRKKaSFxGJYip5EZEoppIXEYliKnkRkSj2/wHx/d6yDaWHWwAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "y_pred.plot(title=\"Predictions\")\n",
    "changes[start_date:end_date].plot(title=\"Actual\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Perform out-of-sample prediction of data past the end of the data we have\n",
    "y_new = results.forecast(steps=10)  # You can also use the predict method with a start/end date in the future:\n",
    "# y_new = results.predict(len(changes), end=len(changes)+10, dynamic=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "results.forecast?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x2153f372f88>]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEDCAYAAAAlRP8qAAAABHNCSVQICAgIfAhkiAAAAAlw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UKBLiKSJBToIiJJQoEuIpIkFOgiIkni/wOVmvhpzDzQiQAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(y_new[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Exercise\n",
    "\n",
    "Compute the SSE value on the predicted values from 2015 onwards. Remember to retrain your model after doing a train/test split before you evaluate!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*For solutions, see `solutions/arima_sse.py`*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Seasonal ARIMA\n",
    "\n",
    "Seasonal variations are not included by default in an ARIMA model. You can approximate this with lag periods of your season, for instance, setting $d=12$. A Seasonal ARIMA model has parameters for both the standard ARIMA model, and additional ones for the seasonality. This gives the full model as: \n",
    "\n",
    "$ARIMA(p, d, q)(P, D, Q)$\n",
    "\n",
    "Alternatively you may see this model written as $ARIMA(p, d, q)x(P, D, Q)$.\n",
    "\n",
    "Where $p$, $d$ and $q$ are as with ARIMA, and $P$, $D$, and $Q$ are the same as their lowercase version, except with a seasonal lag added in. For example,  D is seasonal lag, setting $y_t = y_t - y_{t-M}$ where $M$ is the seasonal lag period (if you have monthly data and want yearly differencing, $M=12$).\n",
    "\n",
    "As with ARIMA, and all the model we have seen so far, any of these values could be zero, effectively turning that part of the model off. Unlike non-seasonal ARIMA, we normally still refer to the model by it's full name, i.e. ARIMA(0, 0, 1)(1, 1, 0), (as opposed to, say, MASAR(1, 1) or some weird combination).\n",
    "\n",
    "In statsmodels, the name of this model is SARIMAX - Seasonal ARIMA, with eXogenous regressors (additional independent variables)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "from statsmodels.tsa.statespace.sarimax import SARIMAX"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\marin\\Anaconda3\\lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:165: ValueWarning: No frequency information was provided, so inferred frequency QS-OCT will be used.\n",
      "  % freq, ValueWarning)\n"
     ]
    }
   ],
   "source": [
    "seasonal_model = SARIMAX(changes, order=(1, 1, 1), seasonal_order=(0, 1, 0, 4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "results = seasonal_model.fit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>Statespace Model Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>               <td>Value</td>             <th>  No. Observations:  </th>    <td>322</td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>           <td>SARIMAX(1, 1, 1)x(0, 1, 0, 4)</td> <th>  Log Likelihood     </th>  <td>891.773</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>                  <td>Mon, 13 May 2019</td>        <th>  AIC                </th> <td>-1777.546</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                      <td>11:14:20</td>            <th>  BIC                </th> <td>-1766.269</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Sample:</th>                   <td>07-01-1949</td>           <th>  HQIC               </th> <td>-1773.041</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th></th>                         <td>- 10-01-2029</td>          <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>              <td>opg</td>              <th>                     </th>     <td> </td>    \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "     <td></td>       <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ar.L1</th>  <td>   -0.3695</td> <td>    0.020</td> <td>  -18.912</td> <td> 0.000</td> <td>   -0.408</td> <td>   -0.331</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>ma.L1</th>  <td>   -0.9999</td> <td>    1.169</td> <td>   -0.856</td> <td> 0.392</td> <td>   -3.290</td> <td>    1.291</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>sigma2</th> <td>    0.0002</td> <td>    0.000</td> <td>    0.850</td> <td> 0.395</td> <td>   -0.000</td> <td>    0.001</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Ljung-Box (Q):</th>          <td>196.94</td> <th>  Jarque-Bera (JB):  </th> <td>7969.37</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Q):</th>                 <td>0.00</td>  <th>  Prob(JB):          </th>  <td>0.00</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Heteroskedasticity (H):</th> <td>713.28</td> <th>  Skew:              </th>  <td>0.66</td>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(H) (two-sided):</th>     <td>0.00</td>  <th>  Kurtosis:          </th>  <td>27.53</td> \n",
       "</tr>\n",
       "</table><br/><br/>Warnings:<br/>[1] Covariance matrix calculated using the outer product of gradients (complex-step)."
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                                 Statespace Model Results                                \n",
       "=========================================================================================\n",
       "Dep. Variable:                             Value   No. Observations:                  322\n",
       "Model:             SARIMAX(1, 1, 1)x(0, 1, 0, 4)   Log Likelihood                 891.773\n",
       "Date:                           Mon, 13 May 2019   AIC                          -1777.546\n",
       "Time:                                   11:14:20   BIC                          -1766.269\n",
       "Sample:                               07-01-1949   HQIC                         -1773.041\n",
       "                                    - 10-01-2029                                         \n",
       "Covariance Type:                             opg                                         \n",
       "==============================================================================\n",
       "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "ar.L1         -0.3695      0.020    -18.912      0.000      -0.408      -0.331\n",
       "ma.L1         -0.9999      1.169     -0.856      0.392      -3.290       1.291\n",
       "sigma2         0.0002      0.000      0.850      0.395      -0.000       0.001\n",
       "===================================================================================\n",
       "Ljung-Box (Q):                      196.94   Jarque-Bera (JB):              7969.37\n",
       "Prob(Q):                              0.00   Prob(JB):                         0.00\n",
       "Heteroskedasticity (H):             713.28   Skew:                             0.66\n",
       "Prob(H) (two-sided):                  0.00   Kurtosis:                        27.53\n",
       "===================================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Covariance matrix calculated using the outer product of gradients (complex-step).\n",
       "\"\"\""
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Exercise\n",
    "\n",
    "1. Check the documentation for SARIMAX on the statsmodels website. These values were set in the previous code example?\n",
    "2. Choose a seasonal commodity from Quandl, such as Wheat, and apply a Seasonal ARIMA to the data."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*For solutions see `solutions/arima_seasonal.py`*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Extended Exercise Automating parameter selection\n",
    "\n",
    "As we saw above, choosing parameters for ARIMA is a fairly straight-forward process, using AIC to choose the best from a subset of features. This process is easily automatable, and has been automated in a few libraries. In the R programming language, the ARIMA implementation already includes it, while it is a separate module for statsmodels in Python. You can get the code from https://github.com/tgsmith61591/pmdarima\n",
    "\n",
    "Install the package on your system and run on the data you received for the exercises in this module (cryptocurrency and seasonal commodity). What parameters does it choose, and how effective was the algorithm?\n",
    "\n",
    "As a warning, automated parameter selection is basically a brute force selection. Generally it composes the following steps:\n",
    "\n",
    "1. Try all parameter combinations from those given\n",
    "2. Evaluate all of them using some metric\n",
    "3. Choose the best one.\n",
    "\n",
    "Some algorithms exist separately to optimise and improve this process by being a bit more clever about their search, but these options are not available in `pmdarima`.\n",
    "\n",
    "Further, the documenation for this library also contains additional information on choosing parameter bounds that is worth reading for a more complete picture of ARIMA."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
